<template>
    <view class="awardlegouitem item">
        <view class="store flexb">
            <view class="store_name flexb">
                <image class="icon" :src="imgpath + 'store_icon.png?v=' + imgVersion" mode="aspectFit" > </image>
                <view class="txt">{{ objInfo.shopname }}</view>
            </view>
            <view class="order_state" :style="([5,6].includes(objInfo.orderstate)  &&  objInfo.retState == 1 || objInfo.orderstate >= 7) ? 'color:#FFB542;' : ''">{{ getState(objInfo) }}</view>
        </view>
        <view class="order-content">
            <view class="prosbox" @click="linkTo('detail')">
                <view class="pros_detail flexb" >
                    <image class="pro-img" :src="objInfo.litpicpath || defaultPro" mode="aspectFill"  @error="objInfo.litpicpath = defaultPro "></image>
                    <view class="pro-info ">
                        <view class="pro_detail flexb">
                            <view class="flex_l">
                                <view class="pro-tit">{{ objInfo.title }}</view>
                                <view class="point" v-if="objInfo.orderstate != '7' && objInfo.point > 0">使用<text>{{objInfo.point}}</text>{{globalData.appConfig.cfg_pointName || '积分'}}</view>
                                <view class="point" v-else-if="objInfo.point > 0"><text>{{objInfo.point}}</text>{{globalData.appConfig.cfg_pointName || '积分'}}已退还</view>
                            </view>
                            <view class="pro-price order-count ">
                                <view class="num">x{{ objInfo.procount }}</view>
                                <view class="flex_r flexb priceb">
                                    <text class="txt">实付</text>
                                    <view class="tprice">
                                        <text class="symbol">{{globalData.appConfig && globalData.appConfig.currency && globalData.appConfig.currency.symbol || '￥'}}</text>
                                        <text class="b">{{ objInfo.totalPayPrice.split('.')[0] }}</text>
                                        <text class="smNumber" v-if=" (parseFloat(objInfo.totalPayPrice)).toString().includes('.')">.{{  (parseFloat(objInfo.totalPayPrice)).toString().split('.')[1] }}</text>
                                    </view>
                                </view>
                            </view>
                        </view>
                        
                    </view>
                </view>
               
            </view>
            <view class="btns_group flexb">
                <block v-if="objInfo.orderstate == '0'">
                    <view class="btn_cancel  btn" @click="linkTo('cancel')">取消订单</view>
                    <view class="btn_pay bgBtn  btn" @click="linkTo('pay')">去付款</view>
                </block>
                <block v-if="objInfo.orderstate == '1'">
                    <!-- <view class="btn_pay bgBtn  btn" @click="linkTo('share')">邀好友参与</view> -->
                    <button open-type="share" @click.stop="linkTo('share')" :data-orderInd="ind" style="margin-right: 0;" class="btn_invite bgBtn btn">邀好友参与</button>
                </block>
                <block v-if="objInfo.orderstate == '5' || objInfo.orderstate == '6'">
                    <view v-if="objInfo.orderstate == '6' && objInfo.retState != 1" class="borderBtn  btn" @click="linkTo('receive')">确认收货</view>
                    <view :class="{'btn_pay btn':true,'bgBtn' : objInfo.retState != 1}" @click="linkTo('detail')">查看活动结果</view>
                </block>
                <block v-if="objInfo.orderstate == '7'">
                    <view class=" btn" @click="linkTo('detail')">查看活动结果</view>
                </block>
            </view>
        </view>
    </view>
</template>

<script>
const app = getApp();
export default {
    props:{
        objInfo:{
            type:Object,
            default:{
                
            }
        },
        ind:{
            type:Number,
            default:0
        }
    },
    computed:{
        getState(){
            return function(order){
                const that = this;
                let state = order.orderstate;
                let stateInfo = '';
                switch (state){
                    case '0' :
                        stateInfo = '待付款';
                        break;
                    case '1' :
                        stateInfo = `还需邀请${order.havenumber}人`;
                        break;
                    case '3' :
                        stateInfo = `交易成功`;
                        break;
                    case '4' :
                        stateInfo = `退款中`;
                        break;
                    case '5' :
                        stateInfo = order.retState == 1 ? `退款中，待商家处理` : `待发货`;
                        break;
                    case '6' :
                        stateInfo = order.retState == 1 ? `退款中，待商家处理` : `已发货`;
                        break;
                    case '7' :
                        stateInfo = `已退款`;
                        break;
                    case '9' :
                        if(order.is_paytuikuanlogtic == 1){//
                            if(order.retExpnumber !='' && order.retExpcompany !=''){
                                stateInfo = '已退货，待商家处理';   //已退货，待商家处理
                            }else{
                                stateInfo = '待上门取件退货';   //待上门取件退货
                            }
                        }else{
                            stateInfo = '待退货';   //待退货--没有支付运费
                        }
                        break;
                }

                return stateInfo
            }
        }
    },
    data(){
        return{
            defaultPro:app.globalData.masterDomain + '/static/images/good_default.png',
            globalData:app.globalData,
            platForm:app.globalData.platForm,
            imgpath:app.globalData.imgPath + '/member/order/',
            masterDomain:app.globalData.masterDomain,
            imgVersion:app.globalData.imgVersion,
        }
    },
    mounted(){
        const that = this;
    },
    methods:{
        /**
         * @param {string} type 类型  detail => 订单详情  receive => 确认收货   pay => 去支付
         * */ 
        linkTo(type){
            const that = this;
            let url = ''
            switch(type){
                case 'detail':
                    url = `${app.globalData.appConfig.cfg_user_index}/orderdetail-awardlegou-${that.objInfo.id}.html`
                    app.linkTo(url,false,false)
                    break;
                case 'pay':
                    uni.$emit('payorder',{objInfo:this.objInfo,ind:this.ind})
                    break;
                case 'receive':
                    uni.$emit('receive',{objInfo:this.objInfo,ind:this.ind})
                    break;
                case 'cancel':
                    uni.$emit('cancelorder',{objInfo:this.objInfo,ind:this.ind})
                    break;
                case 'share':
                    if(app.globalData.platForm == 'web'){
                        uni.$emit('share',{objInfo:this.objInfo,ind:this.ind})
                    }
                    break;
            }
        },

        /**
         * 确认收货
         * */ 
        receive(){
            const that = this;

        }
    },
}
</script>

<style scoped>
@import url(./orderlist_awardlegou.css);
</style>